//
//  BarnnerMsgView.m
//  yixintong
//
//  Created by longzhiyuan on 15/6/8.
//
//

#import "BarnnerMsgView.h"

@implementation BarnnerMsgView


-(void)setFrame:(CGRect)frame
{
    labelShow =[[UILabel alloc]init];
    labelShow.text=@"";
    [self addSubview:labelShow];
    [super setFrame:frame];
    UIView *maskView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width,frame.size.height)];
    [maskView setBackgroundColor:[UIColor grayColor]];
    [self addSubview:maskView];
    [self setMaskView:maskView];
}
-(void)initData:(NSString*)nsStrInfo
{
    //nsStrContentInfo=@"实际frame大小，并将label的frame变成实际大小";
    nsStrContentInfo=nsStrInfo;
    labelShow.text=nsStrContentInfo;
    UIFont *font = [UIFont fontWithName:@"Arial" size:14];
    //设置一个行高上限
    CGSize size = CGSizeMake(1000,2000);
    //计算实际frame大小，并将label的frame变成实际大小
    CGSize labelsize = [labelShow.text sizeWithFont:font constrainedToSize:size lineBreakMode:UILineBreakModeWordWrap];
    [labelShow setFont:font];
    labelShow.lineBreakMode = UILineBreakModeWordWrap;
    [labelShow setFrame:CGRectMake(0, 10, labelsize.width, labelsize.height)];
    self.blnInitData=YES;
}
-(void)setTextColor:(UIColor*)color
{
    [labelShow setTextColor:color];
}
-(void)start
{
    if ([nsStrContentInfo isEqualToString:@""])
    {
        return;
    }
    CGRect frame = labelShow.frame;
    frame.origin.x = -frame.size.width;
    labelShow.frame = frame;
    [UIView beginAnimations:@"testAnimation" context:NULL];
    [UIView setAnimationDuration:8.8f];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    [UIView setAnimationDelegate:self];
    //来回滚动
    [UIView setAnimationRepeatAutoreverses:NO];
    [UIView setAnimationRepeatCount:999999];
    //最终位置
    frame = labelShow.frame;
    frame.origin.x = self.frame.size.width;
    labelShow.frame = frame;
    [UIView commitAnimations];
    
}
- (void)stop
{
    [labelShow.layer removeAllAnimations];
    CGRect frame = labelShow.frame;
    frame.origin.x = 0;
    labelShow.frame = frame;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
